package com.sample.service.impls;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sample.dto.TestDTO;
import com.sample.entity.Test;
import com.sample.mapper.TestMapper;
import com.sample.service.TestService;
import com.swak.annotation.FluxService;
import com.swak.entity.Page;
import com.swak.entity.Parameters;
import com.swak.incrementer.IdGen;
import com.swak.persistence.QueryCondition;
import com.swak.service.BaseService;

/**
 * TestServiceImpl.
 * 
 * @author Auto Generator
 * @date 2023-05-31T10:08:06.622985500
 */
@FluxService
@Service("sampleTestService")
public class TestServiceImpl extends BaseService<Test, Long> implements TestService {

	@Autowired
	private TestMapper testMapper;

	@Override
	public TestDTO get(Long id) {
		return TestDTO.convert(this.testMapper.get(id));
	}

	@Override
	@Transactional
	public TestDTO save(TestDTO test) {
		Test entity = test.transform();
		if (IdGen.isInvalidId(entity.getId())) {
			this.testMapper.insert(entity);
		} else {
			this.testMapper.update(entity);
		}
		return this.get(entity.getId());
	}

	@Override
	@Transactional
	public Integer delete(TestDTO test) {
		Test entity = test.transform();
		return this.testMapper.delete(entity);
	}

	@Override
	public Page<TestDTO> page(TestDTO query, Parameters param) {
		QueryCondition qc = new QueryCondition();
		qc.getCriteria().andEqualTo(Test.DelFlag, Boolean.FALSE);
		qc.setOrderByClause(param.orderBy(Test.DefaultOrderBy));
		return TestDTO.convert(this.testMapper.queryForPage(qc, param));
	}

}
